package com.xunyin.modules.usergrade.rest;

import com.xunyin.api.ApiResult;
import com.xunyin.common.bean.LocalUser;
import com.xunyin.common.interceptor.AuthCheck;
import com.xunyin.modules.log.AppLog;
import com.xunyin.modules.mtusergrade.domain.MtUserGrade;
import com.xunyin.modules.mtusergrade.param.UserGradeParam;
import com.xunyin.modules.mtusergrade.service.mapper.MtUserGradeMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * 会员等级接口controller
 * <p>
 * Created by xunyinyunshang <3594419785@qq.com>
 * CopyRight 讯音云商 https://www.tonetn.com
 */
@Slf4j
@RestController
@Api(value = "会员等级接口相关", tags = "共享空间:会员等级接口相关")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class ClientUserGradeController {

    private final MtUserGradeMapper mtUserGradeMapper;

    /**
     * 根据用户Id,获取用户会员等级
     */
    @AppLog(value = "获取用户会员等级", type = 1)
    @AuthCheck
    @PostMapping("/userGrade/getUserGradeByUserId")
    @ApiOperation(value = "获取用户会员等级", notes = "获取用户会员等级")
    public ApiResult<Map<String, Object>> getUserGradeByUserId(HttpServletRequest request, @RequestBody UserGradeParam param) {
        Long uid = LocalUser.getUser().getUid();
        //Integer userId = param.getUserId();
        Map<String, Object> data = new HashMap();
        MtUserGrade mtUserGrade = mtUserGradeMapper.findUserGradeByUserId(uid.intValue());
        data.put("mtUserGrade", mtUserGrade);
        return ApiResult.ok(data);

    }

}
